home *** CD-ROM | disk | FTP | other *** search
- MODULE tthread;
- __IMP_SWITCHES__
- #if (defined HM2) || (defined HM2_OLD)
- (*$E+ lokale Prozedur als Parameter *)
- #endif
- #ifdef HM2
- #ifdef __LONG_WHOLE__
- (*$!i+: Modul muss mit $i- uebersetzt werden! *)
- (*$!w+: Modul muss mit $w- uebersetzt werden! *)
- #else
- (*$!i-: Modul muss mit $i+ uebersetzt werden! *)
- (*$!w-: Modul muss mit $w+ uebersetzt werden! *)
- #endif
- #endif
-
- VAL_INTRINSIC
- CAST_IMPORT
-
- FROM PORTAB IMPORT
- (* TYPE *) UNSIGNEDWORD, ANYLONG, SIGNEDLONG;
-
- FROM proc IMPORT
- (* TYPE *) WaitVal,
- (* PROC *) tfork, wait, WEXITSTATUS;
-
- FROM InOut IMPORT
- (* PROC *) Read, WriteString, WriteInt, WriteLn;
-
- (*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
-
- VAR
- globalvar : INTEGER;
- ch : CHAR;
-
- (*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
-
- PROCEDURE idle;
- VAR i : UNSIGNEDWORD;
- BEGIN
- FOR i:=0 TO MAX(UNSIGNEDWORD) DO
- END;
- END idle;
-
- PROCEDURE thread1 (arg : ANYLONG): INTEGER;
- VAR i : INTEGER;
- BEGIN
- globalvar := 42;
- FOR i:=1 TO 3 DO
- idle;
- WriteString("``thread1'': "); WriteInt(INT(CAST(SIGNEDLONG,arg)), 0);
- WriteLn;
- END;
- RETURN(11);
- END thread1;
-
- PROCEDURE thread2 (arg : ANYLONG): INTEGER;
- VAR i : INTEGER;
- BEGIN
- FOR i:=1 TO 3 DO
- idle;
- WriteString("``thread2'': "); WriteInt(INT(CAST(SIGNEDLONG,arg)), 0);
- WriteLn;
- END;
- RETURN(22);
- END thread2;
-
-
- VAR pid, pid1, pid2 : INTEGER;
- state : WaitVal;
-
- BEGIN
- globalvar := 0;
- WriteString("``main'': globalvar: "); WriteInt(globalvar, 0); WriteLn;
-
- pid1 := tfork(thread1, 111);
- pid2 := tfork(thread2, 222);
-
- idle;
-
- WriteString("``main'': thread1-pid: "); WriteInt(pid1, 0); WriteLn;
- WriteString("``main'': thread2-pid: "); WriteInt(pid2, 0); WriteLn;
-
- LOOP
- pid := wait(state);
- IF pid < 0 THEN EXIT; END;
- WriteString("``main'': pid "); WriteInt(pid, 0);
- WriteString(" returned: "); WriteInt(WEXITSTATUS(state), 0);
- WriteLn;
- END;
-
- WriteString("``main'': globalvar: "); WriteInt(globalvar, 0); WriteLn;
-
- Read(ch);
- END tthread.
-